package com.swy.shopgroup.service.impl;


import com.swy.shopgroup.ResultUtils;
import com.swy.shopgroup.dao.ShopUserMapper;
import com.swy.shopgroup.entity.Result;
import com.swy.shopgroup.entity.ShopUser;
import com.swy.shopgroup.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class UserServiceImpl implements UserService {

    @Resource
    ShopUserMapper userMapper;

    @Override
    public Result insertUser(ShopUser user) {
        return ResultUtils.success("注册成功", userMapper.insert(user));
    }

    @Override
    public Result updateUser(ShopUser user) {
        return ResultUtils.success("用户信息修改成功", userMapper.updateByPrimaryKey(user));
    }

    @Override
    public Result selectById(Long id) {
        ShopUser user = userMapper.selectByPrimaryKey(id);
        if (user == null) {
            return ResultUtils.success("查询成功", user);
        } else {
            return ResultUtils.err();
        }
    }

    @Override
    public Result login(String name, String pwd) {
        ShopUser user = userMapper.login(name,pwd);
        if (user != null) {
            return ResultUtils.success("登录成功", user);
        } else {
            return ResultUtils.err("用户名或密码错误");
        }
    }
}
